from pathlib import Path
from docu_kit.runs.run import Run


class Window_Run(Run):
    def batch_rename_file_or_folder(self, path, old_word, new_word):
        def execute_func(file_path):
            folder_path = Path(file_path)
            if folder_path.is_dir():
                for item in folder_path.iterdir():
                    if old_word in item.name:
                        new_name = item.name.replace(old_word, new_word)
                        new_path = item.parent / new_name
                        item.rename(new_path)
                        self.logger.info(f"{item} 已成功重命名为 {new_path}")

        self.logger.info("开始重命名")
        self.deep_search_folder(path, execute_func)
        execute_func(path)
        self.logger.info("重命名完成")
